import {
  list
} from "@/api/commodityDetail"
import {
  token_expires
} from '@/utils/Keyword'
const commodityDetail = {
  state: {
    lists: "",
    attrsArry:[]
  },
  mutations: {
    COMMODITY_LIST: (state, data) => {
      if (data) {
        state.lists = data;
      }
    },
    COMMIT_ATTR_ADD: (state, data) => {
      state.attrsArry=[];
      if(data.goods){
         data.goods.saleAttrs.forEach(function(){
          state.attrsArry.push(0)
         })
      }
    }
  },
  actions: {
    COMMODITYLIST({
      commit,
      state
    }, info) {
      return new Promise((resolve, reject) => {
        list(info).then(res => {
          if (res != token_expires) {
            commit("COMMODITY_LIST", res);
            commit("COMMIT_ATTR_ADD", res);
            resolve(res)
          } else {
            resolve(token_expires)
          }
        }).catch(err => {
          resolve(false)
        })
      })
    }
  }
}
export default commodityDetail
